import { error } from 'console'
import { UseFlieType } from './interface/cmd'
import { command, getUse, useLog } from './pkg/cmd'
import useJsonMode from './pkg/useJson'
// import uesJsonMode from './pkg/useJson'
import useProtoMode from './pkg/useProto'
import { getFileType } from './utils'

export default async function main() {
  const { scourePath, option } = command()
  const fileType = getFileType(scourePath)
  switch (fileType) {
    case UseFlieType.proto:
      // 使用proto文件
      await start(useProtoMode(scourePath, option))
      break
    case UseFlieType.json:
      // 使用json文件
      if (option.t === 'default') {
        useLog.err('You must select the tag tag to convert')
        process.exit(1)
      }
      await useJsonMode(scourePath, option)
      break
    default:
      getUse('Only JSON or Proto format files are accepted')
      process.exit(1)
  }
}
async function start(fn: Promise<void | [void, void]>) {
  try {
    await fn
    useLog.success('success')
  } catch (error: any) {
    useLog.err(error)
  }
}
main()
